package com.simple.cms.model.mapper;


import com.simple.cms.common.utils.DateUtil;
import com.simple.cms.common.utils.MoneyUtils;
import org.apache.commons.lang3.StringUtils;
import org.modelmapper.AbstractConverter;
import org.modelmapper.Converter;

import java.math.BigDecimal;
import java.util.Date;

class BaseConverter {

    static Converter<Long, String> ToMoneyYuan = new AbstractConverter<Long, String>() {
        protected String convert(Long source) {
            return MoneyUtils.toYuan(source);
        }
    };

    static Converter<String, Integer> StringToInt = new AbstractConverter<String, Integer>() {
        protected Integer convert(String source) {
            return StringUtils.isEmpty(source) ? 0 : Integer.valueOf(source);
        }
    };

    static Converter<Integer, String> IntToString = new AbstractConverter<Integer, String>() {
        protected String convert(Integer source) {
            return Integer.toString(source);
        }
    };

    static Converter<Date, String> DateToString = new AbstractConverter<Date, String>() {
        protected String convert(Date source) {
            return DateUtil.dateToString(source);
        }
    };

}
